<div class="layui-fluid layui-anim febs-anim" id="businesses-student" lay-title="我的学生">
    <div class="layui-row febs-container">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body febs-table-full">
                    <form class="layui-form layui-table-form" lay-filter="college-table-form">
                        <input id="userId" type="hidden" data-th-value="${user.userId}">
                        <fieldset class="layui-elem-field layui-field-title" style="">
                            <legend style="font-size: 15px; font-weight: bolder;">批量查询</legend>
                        </fieldset>
                        <div class="layui-row">
                            <div class="layui-col-md10">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">批次</label>
                                        <div id="stubatch" class="layui-input-inline"></div>
                                        <label class="layui-form-label layui-form-label-sm">院校</label>
                                        <div id="stucollege" class="layui-input-inline"></div>
                                        <label class="layui-form-label layui-form-label-sm">专业</label>
                                        <div id="stumajor" class="layui-input-inline"></div>
                                        <label class="layui-form-label layui-form-label-sm">层次</label>
                                        <div class="layui-input-inline">
                                            <select name="level" id="stuidlevel">
                                                <option value=""></option>
                                                <option value="1">专升本</option>
                                                <option value="3">高起专</option>
                                                <option value="2">高起本</option>
                                            </select>
                                        </div>
                                        <label class="layui-form-label layui-form-label-sm">阶段</label>
                                        <div class="layui-input-inline">
                                            <select id="stuidstage" name="stageId">
                                                <option value=""></option>
                                                <option value="14">考前</option>
                                                <option value="15">在籍</option>
                                                <option value="16">逾期毕业</option>
                                                <option value="17">已毕业</option>
                                            </select>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <fieldset class="layui-elem-field layui-field-title" style="">
                            <legend style="font-size: 15px; font-weight: bolder;">精准查询</legend>
                        </fieldset>
                        <div class="layui-row">
                            <div class="layui-col-md10">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">姓名</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="stuName" autocomplete="off" class="layui-input"
                                                   id="stuidstuname">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">身份证</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="identity" autocomplete="off" class="layui-input"
                                                   id="stuididentity">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">电话</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="tel" autocomplete="off" class="layui-input"
                                                   id="stuidtel">
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md2 layui-col-sm12 layui-col-xs12 table-action-area">
                                <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-blue-plain table-action"
                                     id="stuquery">
                                    <i class="layui-icon">&#xe848;</i>
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-green-plain table-action"
                                     id="stureset">
                                    <i class="layui-icon">&#xe79b;</i>
                                </div>
                            </div>
                        </div>
                        <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                            <div class="layui-row">
                                <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-green-plain table-action"
                                >
                                    <i id="task" class="layui-icon ">审核信息</i>
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-blue-plain table-action"
                                     id="movtorecycle">
                                    <i class="layui-icon layui-icon-reload">移入回收站</i>
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-green-plain table-action"
                                     id="labelLog">
                                    <i class="layui-icon layui-icon-log">创建标记</i>
                                </div>
                                <div class="layui-inline" id="studentLabels">
                                    <label class="layui-form-label layui-form-label-sm">你的标签:</label>
                                </div>
                            </div>
                        </blockquote>
                    </form>
                    <table lay-filter="studentTable" lay-data="{id: 'studentTable'}"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/html" id="student-option">
    <a lay-event="detail" title="查看详情"><i
            class="layui-icon febs-edit-area febs-green">&#xe7a5;</i></a>
    <!--<a lay-event="edit"><i-->
    <!--class="layui-icon febs-edit-area febs-blue">&#xe7a4;</i></a>-->
</script>
<script data-th-inline="none" type="text/javascript">
    layui.use(['dropdown', 'jquery', 'form', 'table', 'febs', 'xmSelect'], function () {
        let $ = layui.jquery,
            febs = layui.febs,
            form = layui.form,
            xmSelect = layui.xmSelect,
            table = layui.table,
            dropdown = layui.dropdown,
            $view = $('#businesses-student'),
            $query = $view.find('#stuquery'),
            $reset = $view.find('#stureset'),
            $searchForm = $view.find('form'),
            sortObject = {field: 'createDate', type: null},
            stubatchSelect,
            stumajorSelect,
            stueamXmSelect,
            tableIns;
        form.render();
        initTable();
        stugetLabel();
        setstueamXmSelect();
        setstumajorSelect();
        setstubatchSelect();

        $(".layui-input").keydown(function (e) {//当按下按键时
            if (e.which == 13) {//.which属性判断按下的是哪个键，回车键的键位序号为13
                $query.click();
            }
        });

        function setstubatchSelect() {
            stubatchSelect = xmSelect.render({
                el: '#stubatch',
                //toolbar: {show: true},
                name: 'batchId',
                filterable: true,
                radio: true,
                theme: {
                    color: '#32c787',
                },
                model: {
                    label: {
                        type: 'text',
                        text: {
                            //左边拼接的字符
                            left: '',
                            //右边拼接的字符
                            right: '',
                            //中间的分隔符
                            separator: ', ',
                        },
                    }
                },
                prop: {
                    name: 'batchName',
                    value: 'id'
                },
                data: []
            });
            febs.get('/student/batchList', null, function (data) {
                stubatchSelect.update({
                    data: data.data,
                    autoRow: true,
                })
            });
        }

        function setstueamXmSelect() {
            stueamXmSelect = xmSelect.render({
                el: '#stucollege',
                //toolbar: {show: true},
                name: 'collegeId',
                filterable: true,
                radio: true,
                theme: {
                    color: '#32c787',
                },
                model: {
                    label: {
                        type: 'text',
                        text: {
                            //左边拼接的字符
                            left: '',
                            //右边拼接的字符
                            right: '',
                            //中间的分隔符
                            separator: ', ',
                        },
                    }
                },
                prop: {
                    name: 'name',
                    value: 'id'
                },
                data: []
            });


            febs.get('/student/collegeList', null, function (data) {
                stueamXmSelect.update({
                    data: data.data,
                    autoRow: true,
                })
            });
        }

        function setstumajorSelect() {
            stumajorSelect = xmSelect.render({
                el: '#stumajor',
                // toolbar: {show: true},
                name: 'majorId',
                filterable: true,
                radio: true,
                theme: {
                    color: '#32c787',
                },
                model: {
                    label: {
                        type: 'text',
                        text: {
                            //左边拼接的字符
                            left: '',
                            //右边拼接的字符
                            right: '',
                            //中间的分隔符
                            separator: ', ',
                        },
                    }
                },
                prop: {
                    name: 'fullName',
                    value: 'id'
                },
                data: []
            });

            febs.get('/student/majorList', null, function (data) {
                stumajorSelect.update({
                    data: data.data,
                    autoRow: true,
                })
            });
        }

        dropdown.render({
            elem: $view.find('.action-more'),
            click: function (name, elem, event) {
                let checkStatus = table.checkStatus('studentTable');
                if (name === 'add') {
                    febs.modal.open('新增院校', 'college/add', {
                        btn: ['提交', '重置'],
                        area: $(window).width() <= 750 ? '95%' : '50%',
                        yes: function (index, layero) {
                            $('#college-add').find('#submit').trigger('click');
                        },
                        btn2: function () {
                            $('#college-add').find('#reset').trigger('click');
                            return false;
                        }
                    });
                }
                if (name === 'delete') {
                    if (!checkStatus.data.length) {
                        febs.alert.warn('请选择需要删除的院校');
                    } else {
                        febs.modal.confirm('提示', '确定删除该院校？', function () {
                            let collegeIds = [];
                            layui.each(checkStatus.data, function (key, item) {
                                collegeIds.push(item.id)
                            });
                            deleteColleges(collegeIds.join(','));
                        });
                    }
                }
                if (name === 'export') {
                    let params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
                    params.pageSize = $view.find(".layui-laypage-limits option:selected").val();
                    params.pageNum = $view.find(".layui-laypage-em").next().html();
                    febs.download(ctx + 'college/excel', params, '院校信息表.xlsx');
                }
            },
            options: [{
                name: 'add',
                title: '新增院校',
                perms: 'college:add'
            }, {
                name: 'delete',
                title: '删除院校',
                perms: 'college:delete'
            }, {
                name: 'export',
                title: '导出Excel',
                perms: 'college:export'
            }]
        });

        table.on('tool(studentTable)', function (obj) {
            let data = obj.data,
                layEvent = obj.event;
            if (layEvent === 'detail') {
                febs.modal.view('学生信息', 'student/detail/' + data.id, {
                    area: ['70%', '80%'],
                    tipsMore: true
                });
            }
            if (layEvent === 'del') {
                febs.modal.confirm('提示', '确定删除该院校？', function () {
                    deleteColleges(data.id);
                });
            }
            if (layEvent === 'edit') {
                febs.modal.open('修改院校', 'college/update/' + data.id, {
                    area: $(window).width() <= 750 ? '90%' : '50%',
                    btn: ['提交', '取消'],
                    yes: function (index, layero) {
                        $('#college-update').find('#submit').trigger('click');
                    },
                    btn2: function () {
                        layer.closeAll();
                    }
                });
            }
        });

        table.on('sort(studentTable)', function (obj) {
            sortObject = obj;
            tableIns.reload({
                initSort: obj,
                where: $.extend(getQueryParams(), {
                    field: obj.field,
                    order: obj.type
                })
            });
        });


        $query.on('click', function () {
            let params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
            tableIns.reload({where: params, page: {curr: 1}});
        });

        $reset.on('click', function () {
            $searchForm[0].reset();
            sortObject.type = 'null';
            tableIns.reload({where: getQueryParams(true), page: {curr: 1}, initSort: sortObject});
            var collegeIds = new Array();
            collegeIds.push('');
            stueamXmSelect.setValue(collegeIds);
            var batchIds = new Array();
            batchIds.push('');
            stubatchSelect.setValue(batchIds);
            var majorIds = new Array();
            majorIds.push('');
            stumajorSelect.setValue(majorIds);
        });

        function initTable() {
            tableIns = febs.table.init({
                elem: $view.find('table'),
                id: 'studentTable',
                url: ctx + 'student/list',
                cols: [[
                    {type: 'checkbox'},
                    {field: 'id', title: '序号', minWidth: 80},
                    {field: 'stuName', title: '姓名', minWidth: 80},
                    {field: 'collegeName', title: '院校', minWidth: 80},
                    {field: 'batchName', title: '批次', minWidth: 80},
                    {field: 'levelname', title: '层次', minWidth: 80},
                    {
                        field: 'stageId', title: '阶段', width: 110,
                        templet: function (obj) {
                            var exep;
                            if (obj.stageId == 14) {
                                exep = '考前';
                            } else if (obj.stageId == 15) {
                                exep = '在籍';
                            } else if (obj.stageId == 16) {
                                exep = '逾期毕业';
                            } else if (obj.stageId == 17) {
                                exep = '已毕业';
                            }
                            return exep;
                        }
                    },
                    {field: 'majorName', title: '专业', minWidth: 80},
                    {field: 'className', title: '班级名称', minWidth: 80},
                    {field: 'userName', title: '班主任', minWidth: 80},
                    {field: 'tel', title: '电话', minWidth: 80},
                    {field: 'identity', title: '身份证', minWidth: 80},
                    {title: '操作', toolbar: '#student-option', minWidth: 140},
                ]],

            });
        }

        function getQueryParams(flag) {
            let params = $searchForm.serializeJson();
            return params;
        }

        //待办任务点击
        $("#task").click(function () {
            febs.modal.open('审核信息', 'student/goUserTaskList/' + $("#userId").val(), null, {
                area: ['50%', '30%']
            });

        })

        $("#movtorecycle").click(function () {
            let checkStatus = table.checkStatus('studentTable');
            let studentIds = [];
            layui.each(checkStatus.data, function (key, item) {
                studentIds.push(item.id)
            });
            if (studentIds.length > 0) {
                febs.modal.confirm('提示', '确定移入回收站吗？', function () {
                    recycleStudent(studentIds.join(','));
                });
            } else {
                febs.alert.warn('请选择学生!');
            }
        });

        function recycleStudent(studentIds) {
            febs.get(ctx + 'student/moveToRecycle/' + studentIds, null, function () {
                febs.alert.success('学生回收成功');
                $query.click();
            });
        };
        $("#overdue").click(function () {
            let checkStatus = table.checkStatus('studentTable');
            febs.modal.confirm('提示', '确定让他的状态变为逾期毕业吗？', function () {
                let studentIds = [];
                layui.each(checkStatus.data, function (key, item) {
                    studentIds.push(item.id)
                });
                overdueSet(studentIds.join(','));
                console.log(studentIds);
            });
        });

        function overdueSet(studentIds) {
            febs.get(ctx + 'student/overdueSet/' + studentIds, null, function () {
                febs.alert.success('让他变为逾期毕业状态成功');
                $query.click();
            });
        };

        $("#labelLog").click(function () {
            febs.modal.open('创建标记', 'student/label', {
                btn: ['提交', '重置'],
                area: $(window).width() <= 400 ? '95%' : '50%',
                yes: function (index, layero) {
                    $('#label-add').find('#submit').trigger('click');
                },
                btn2: function () {
                    $('#label-add').find('#reset').trigger('click');
                    return false;
                }
            });
        });

        function stugetLabel() {
            var h1 = "";
            $.ajax({
                type: "GET",
                url: "student/checkYourLabel/",
                success: function (data) {
                    for (var i = 0; i < data.length; i++) {
                        h1 = $("<div class=\"layui-btn layui-btn-sm layui-btn-primary febs-button-blue-plain table-action\">\n" +
                            "<i class='add_project_student'  name='" + data[i].labelName + "' value='" + data[i].conditionContent + "'>" + data[i].labelName + "</i>" +
                            "<i> </i><i> </i><i class='del_project_student'  value='" + data[i].id + "'><i class='layui-icon'></i></i>" +
                            "</div>");
                        $("#studentLabels").after(h1);
                    }
                },
            });
        };


        $(document).on("click", ".del_project_student", function () {
            var labelid = $(this).attr("value");
            console.log($(this).attr("value"));
            febs.modal.confirm('提示', '要删除此标签吗？', function () {
                $.ajax({
                    type: "DELETE",
                    url: "student/delLabel/",
                    data: {id: labelid},
                    success: function (data) {
                        febs.alert.success('标签删除成功');
                        $("#studentLabels").nextAll().remove();
                        stugetLabel();
                    },
                });
            });

        });

        $(document).on("click", ".add_project_student", function () {
            var lvalue = $.parseJSON($(this).attr("value"));
            var collegeIds = new Array();
            collegeIds.push(lvalue.collegeId);
            stueamXmSelect.setValue(collegeIds);
            var batchIds = new Array();
            batchIds.push(lvalue.batchId);
            stubatchSelect.setValue(batchIds);
            var majorIds = new Array();
            majorIds.push(lvalue.majorId);
            stumajorSelect.setValue(majorIds);
            $("#stuidstuname").val(lvalue.stuName);
            $("#stuididentity").val(lvalue.identity);
            $("#stuidtel").val(lvalue.tel);
            $("#stuidstage").val(lvalue.stageId);
            layui.form.render("select");
            $("#stuidlevel").val(lvalue.level);
            layui.form.render("select");//动态选择
        });

        //获取待办任务数量
        $(function () {
            $.ajax({
                type: "get",
                url: "/student/getTaskNum",
                data: {"userId": $("#userId").val()},
                success: function (res) {
                    $("#task").text("审核信息(" + res.data + ")")
                }
            })
        })

    });


</script>
